package tmhm.shemes;

import java.awt.Point;
import java.util.ArrayList;

import tmhm.components.*;
import tmhm.gui.*;


public class Intr3 {

    private static CD CD1, CD2;
    private static BoolsToInt UINT, UEXT;
    private static TSB TSBUINTout3, TSBUEXTout3;
    private static IntToInt IBUS3low;
    private static REG BR;
    private static IntToBools BRbits;
    private static BoolsToInt IVTDSP;
    private static TSB TSBIVTDSPout3;
    private static REG IVTP;
    private static TSB TSBIVTPout1;
    private static GuiScheme gui;

    public static GuiScheme getGui() {
        return gui;
    }

    public static void init() {
        CD1 = new CD(4);
        CD2 = new CD(8);

        UINT = new BoolsToInt(8, 8);
        UEXT = new BoolsToInt(8, 8);

        TSBUINTout3 = new TSB();
        TSBUINTout3.getOut(0).setNumOfLines(16);
        TSBUEXTout3 = new TSB();
        TSBUEXTout3.getOut(0).setNumOfLines(16);

        IBUS3low = new IntToInt(16, 8);

        BR = new REG(1, "BR");
        BR.getOut(0).setIsInt();
        BR.getOut(0).setNumOfLines(8);

        BRbits = new IntToBools(8, 8);
        IVTDSP = new BoolsToInt(16, 16);
        TSBIVTDSPout3 = new TSB();
        TSBIVTDSPout3.getOut(0).setNumOfLines(16);

        IVTP = new REG(1, "IVTP");
        IVTP.getOut(0).setIsInt();
        IVTP.getOut(0).setNumOfLines(16);

        TSBIVTPout1 = new TSB();
        TSBIVTPout1.getOut(0).setNumOfLines(16);

    }

    public static void connect() {

        CD1.setE(new Pin(true));
        CD1.setInputPin(0, Exec2.PSWT());
        CD1.setInputPin(1, Intr1.PRINM());
        CD1.setInputPin(2, Intr1.PRADR());
        CD1.setInputPin(3, Intr1.PRCOD());

        UINT.setInputPin(0, CD1.getOut(0));
        UINT.setInputPin(1, CD1.getOut(1));
        for (int i = 2; i < 8; i++) {
            UINT.setInputPin(i, new Pin(false));
        }

        TSBUINTout3.setInputPin(0, UINT.getOut(0));
        TSBUINTout3.setCtrl(Oper1.UINTout3());
        Bus1.addOnIBUS3(TSBUINTout3.getOut(0));

        CD2.setE(new Pin(true));
        CD2.setInputPin(0, new Pin(false));
        CD2.setInputPin(1, Intr2.irm1());
        CD2.setInputPin(2, Intr2.irm2());
        CD2.setInputPin(3, Intr2.irm3());
        CD2.setInputPin(4, Intr2.irm4());
        CD2.setInputPin(5, Intr2.irm5());
        CD2.setInputPin(6, Intr2.irm6());
        CD2.setInputPin(7, Intr2.irm7());

        UEXT.setInputPin(0, CD2.getOut(0));
        UEXT.setInputPin(1, CD2.getOut(1));
        UEXT.setInputPin(2, CD2.getOut(2));
        UEXT.setInputPin(3, new Pin(true));
        for (int i = 4; i < 8; i++) {
            UEXT.setInputPin(i, new Pin(false));
        }

        TSBUEXTout3.setInputPin(0, UEXT.getOut(0));
        TSBUEXTout3.setCtrl(Oper1.UEXTout3());
        Bus1.addOnIBUS3(TSBUEXTout3.getOut(0));

        IBUS3low.setInputPin(0, Bus1.IBUS3());
        BR.setInputPin(0, IBUS3low.getOut(0));
        BR.setPinLd(Oper1.ldBR());
        BRbits.setInputPin(0, BR.getOut(0));

        IVTDSP.setInputPin(0, new Pin(false));
        for (int i = 0; i < 8; i++) {
            IVTDSP.setInputPin(1 + i, BRbits.getOut(i));
        }
        for (int i = 9; i < 16; i++) {
            IVTDSP.setInputPin(i, new Pin(false));
        }

        TSBIVTDSPout3.setInputPin(0, IVTDSP.getOut(0));
        TSBIVTDSPout3.setCtrl(Oper1.IVTDSPout3());
        Bus1.addOnIBUS3(TSBIVTDSPout3.getOut(0));

        IVTP.setInputPin(0, Bus1.IBUS3());
        IVTP.setPinLd(Oper1.ldIVTP());

        TSBIVTPout1.setInputPin(0, IVTP.getOut(0));
        TSBIVTPout1.setCtrl(Oper1.IVTPout1());
        Bus1.addOnIBUS1(TSBIVTPout1.getOut(0));

    }

    public static void gui() {
        GuiLine line; // Pomocna promenljiva
        gui = new GuiScheme("tmhm/tmhm/images/Intr3.png");

        ArrayList<ArrayList<Point>> sections;
        ArrayList<Point> points;



sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(500,42));
points.add(new Point(500,693));
sections.add(points);
line=new GuiLine(sections,Bus1.IBUS1());
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(481,57));
points.add(new Point(481,678));
sections.add(points);
line=new GuiLine(sections,Bus1.IBUS2());
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(462,72));
points.add(new Point(462,663));
sections.add(points);
line=new GuiLine(sections,Bus1.IBUS3());
gui.addLine(line);



sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(154,117));
points.add(new Point(161,117));
sections.add(points);
line=new GuiLine(sections,Intr1.PRCOD());
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(154,132));
points.add(new Point(161,132));
sections.add(points);
line=new GuiLine(sections,Intr1.PRADR());
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(154,147));
points.add(new Point(161,147));
sections.add(points);
line=new GuiLine(sections,Intr1.PRINM());
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(154,162));
points.add(new Point(161,162));
sections.add(points);
line=new GuiLine(sections,Exec2.PSWT());
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(229,72));
points.add(new Point(236,72));
sections.add(points);
line=new GuiLine(sections,new Pin(false));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(229,102));
points.add(new Point(236,102));
sections.add(points);
line=new GuiLine(sections,new Pin(false));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(229,117));
points.add(new Point(236,117));
sections.add(points);
line=new GuiLine(sections,new Pin(false));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(206,132));
points.add(new Point(236,132));
sections.add(points);
line=new GuiLine(sections,CD1.getOut(1));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(206,147));
points.add(new Point(236,147));
sections.add(points);
line=new GuiLine(sections,CD1.getOut(0));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(258,109));
points.add(new Point(364,109));
sections.add(points);
line=new GuiLine(sections,UINT.getOut(0));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(376,115));
points.add(new Point(376,120));
sections.add(points);
line=new GuiLine(sections,Oper1.UINTout3());
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(386,109));
points.add(new Point(462,109));
sections.add(points);
line=new GuiLine(sections,TSBUINTout3.getOut(0));
gui.addLine(line);



sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(154,307));
points.add(new Point(161,307));
sections.add(points);
line=new GuiLine(sections,new Pin(false));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(154,292));
points.add(new Point(161,292));
sections.add(points);
line=new GuiLine(sections,Intr2.irm1());
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(154,277));
points.add(new Point(161,277));
sections.add(points);
line=new GuiLine(sections,Intr2.irm2());
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(154,262));
points.add(new Point(161,262));
sections.add(points);
line=new GuiLine(sections,Intr2.irm3());
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(154,247));
points.add(new Point(161,247));
sections.add(points);
line=new GuiLine(sections,Intr2.irm4());
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(154,232));
points.add(new Point(161,232));
sections.add(points);
line=new GuiLine(sections,Intr2.irm5());
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(154,217));
points.add(new Point(161,217));
sections.add(points);
line=new GuiLine(sections,Intr2.irm6());
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(154,202));
points.add(new Point(161,202));
sections.add(points);
line=new GuiLine(sections,Intr2.irm7());
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(229,194));
points.add(new Point(236,194));
sections.add(points);
line=new GuiLine(sections,new Pin(false));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(229,224));
points.add(new Point(236,224));
sections.add(points);
line=new GuiLine(sections,new Pin(true));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(206,240));
points.add(new Point(236,240));
sections.add(points);
line=new GuiLine(sections,CD2.getOut(2));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(206,255));
points.add(new Point(236,255));
sections.add(points);
line=new GuiLine(sections,CD2.getOut(1));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(206,270));
points.add(new Point(236,270));
sections.add(points);
line=new GuiLine(sections,CD2.getOut(0));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(258,232));
points.add(new Point(364,232));
sections.add(points);
line=new GuiLine(sections,UEXT.getOut(0));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(376,236));
points.add(new Point(376,243));
sections.add(points);
line=new GuiLine(sections,Oper1.UEXTout3());
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(386,232));
points.add(new Point(462,232));
sections.add(points);
line=new GuiLine(sections,TSBUEXTout3.getOut(0));
gui.addLine(line);



sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(278,351));
points.add(new Point(278,328));
points.add(new Point(462,328));
sections.add(points);
line=new GuiLine(sections,IBUS3low.getOut(0));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(195,360));
points.add(new Point(203,360));
sections.add(points);
line=new GuiLine(sections,LogicalComponent.getCPUCLK());
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(195,379));
points.add(new Point(203,379));
sections.add(points);
line=new GuiLine(sections,Oper1.ldBR());
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(278,388));
points.add(new Point(278,421));
sections.add(points);
line=new GuiLine(sections,BR.getOut(0));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(308,434));
points.add(new Point(308,440));
sections.add(points);
line=new GuiLine(sections, new Pin(false));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(218,434));
points.add(new Point(218,440));
sections.add(points);
line=new GuiLine(sections,new Pin(false));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(248,434));
points.add(new Point(248,440));
sections.add(points);
line=new GuiLine(sections,new Pin(false));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(263,434));
points.add(new Point(263,440));
sections.add(points);
line=new GuiLine(sections,BRbits.getOut(7));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(293,434));
points.add(new Point(293,440));
sections.add(points);
line=new GuiLine(sections,BRbits.getOut(0));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(252,464));
points.add(new Point(252,490));
points.add(new Point(364,490));
sections.add(points);
line=new GuiLine(sections,IVTDSP.getOut(0));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(376,495));
points.add(new Point(376,501));
sections.add(points);
line=new GuiLine(sections,Oper1.IVTDSPout3());
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(386,490));
points.add(new Point(462,490));
sections.add(points);
line=new GuiLine(sections,TSBIVTDSPout3.getOut(0));
gui.addLine(line);



sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(278,558));
points.add(new Point(278,535));
points.add(new Point(462,535));
sections.add(points);
line=new GuiLine(sections,Bus1.IBUS3());
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(195,567));
points.add(new Point(202,567));
sections.add(points);
line=new GuiLine(sections,LogicalComponent.getCPUCLK());
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(195,586));
points.add(new Point(202,586));
sections.add(points);
line=new GuiLine(sections,Oper1.ldIVTP());
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(278,596));
points.add(new Point(278,622));
points.add(new Point(364,622));
sections.add(points);
line=new GuiLine(sections,IVTP.getOut(0));
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(376,627));
points.add(new Point(376,633));
sections.add(points);
line=new GuiLine(sections,Oper1.IVTPout1());
gui.addLine(line);
sections=new ArrayList<ArrayList<Point>>();
points=new ArrayList<Point>();
points.add(new Point(386,622));
points.add(new Point(500,622));
sections.add(points);
line=new GuiLine(sections,TSBIVTPout1.getOut(0));
gui.addLine(line);


        // LABELE:
        gui.addLabel(new GuiLabel(504, 118, Bus1.IBUS1()));
        gui.addLabel(new GuiLabel(485, 138, Bus1.IBUS2()));
        gui.addLabel(new GuiLabel(466, 158, Bus1.IBUS3()));
        gui.addLabel(new GuiLabel(302, 532, Bus1.IBUS3()));
        gui.addLabel(new GuiLabel(302, 324, IBUS3low.getOut(0)));
        gui.addLabel(new GuiLabel(286, 124, UINT.getOut(0)));
        gui.addLabel(new GuiLabel(423, 124, TSBUINTout3.getOut(0)));
        gui.addLabel(new GuiLabel(286, 247, UEXT.getOut(0)));
        gui.addLabel(new GuiLabel(423, 247, TSBUEXTout3.getOut(0)));
        gui.addLabel(new GuiLabel(281, 417, BR.getOut(0)));
        gui.addLabel(new GuiLabel(281, 505, IVTDSP.getOut(0)));
        gui.addLabel(new GuiLabel(281, 637, IVTP.getOut(0)));
        gui.addLabel(new GuiLabel(415, 618, TSBIVTPout1.getOut(0)));
    }

    public static Pin UINT() {
        return UINT.getOut(0);
    }

    public static Pin UEXT() {
        return UEXT.getOut(0);
    }

    public static Pin BR() {
        return BR.getOut(0);
    }

    public static Pin IVTP() {
        return IVTP.getOut(0);
    }

    public static Pin IVTDSP() {
        return IVTDSP.getOut(0);
    }

    public static Pin IVTPout() {
        return TSBIVTPout1.getOut(0);
    }

    public static Pin IVTDSPout() {
        return TSBIVTDSPout3.getOut(0);
    }

    public static REG RegBR() {
        return BR;
    }

    public static REG RegIVTP() {
        return IVTP;
    }
}
